home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / langwn1.exe / SAMPLE04.BAS < prev    next >
BASIC Source File  |  1993-03-20  |  53KB  |  1,422 lines

  1. ' giving your user a set of scrollable lists, with files and
  2. ' sub-directories that can be selected, is a common GUI technique.
  3. ' SAMPLE04.BAS shows how to use LangWin to achieve this effect.
  4.  
  5. ' a mode 4 (wallpaper) window is used as background.
  6. ' several unmovable windows (of the same
  7. ' color as background window) with no shadows,
  8. ' are created to provide several
  9. ' scrollable lists in "one" window.
  10.  
  11. ' the directory and file access routines are used to create
  12. ' scrollable lists of files and sub-directories. by clicking
  13. ' on a sub-directory, you can change into it, and it's contents
  14. ' (files and directories) will then be displayed in the scrollable
  15. ' lists.
  16.  
  17. ' this sample also shows how to use an error recovery routine
  18. ' in the main module to detect when a drive is not ready,
  19. ' and allow the user to retry or quit the operation.
  20.  
  21. ' subroutine DoFiles (which also calls ChgPath and SortIt) is
  22. ' meant to be a stand-alone routine that you can copy and use
  23. ' in your own programs. it implements techniques to create
  24. ' a "menu" with drives, sub-directories, files, and the current directory.
  25. ' these can be scrolled, selected, and/or changed.
  26.  
  27.  
  28. DECLARE FUNCTION ChgPath% (NewPath$)   ' changes to new path
  29. DECLARE SUB DoFiles ()                 ' menu of files, dirs, drives
  30. DECLARE SUB SortIt (s$())              ' bubble sort
  31. DECLARE SUB Main ()                    ' main window
  32. DECLARE FUNCTION VidType% ()           ' gets type of monitor
  33. DECLARE SUB ProcessFiles (Qual$, Text$())  ' sample routine to process files
  34.  
  35. '  must compile with qb /ah /L langwin
  36.  
  37. '$DYNAMIC  make all arrays dynamic
  38.  
  39. DEFINT A-Z
  40.  
  41. '$INCLUDE: 'LANGWIN.BI' ' TYPE, DECLARE and COMMON definitions for LangWin.
  42. '                         NOTE: LANGWIN.BI contains all definitions found
  43. '                               in QB.BI, so include for QB.BI is not needed.
  44.  
  45.  
  46.  
  47. CLEAR , , 5000   ' set stack at 5000 bytes
  48.  
  49.  
  50. '---------------------------------------------------------------
  51. ' first see if EGA or VGA monitor
  52. mm = VidType
  53. IF mm <> 3 AND mm <> 4 THEN
  54.     BEEP
  55.     PRINT
  56.     PRINT "LangWin's GUI only supports EGA and VGA."
  57.     PRINT
  58.     END
  59. END IF
  60.  
  61. '----------------------------------------------------------------
  62. ' SHARED VARIABLES
  63.  
  64. ' - dlett$:  MUST contain the letter of the drive that is being
  65. '       referenced by the GetCurDir$ function.
  66. '       if the drive is not ready, the error routine in the main module will
  67. '       get control and use dlett$ in its error message.
  68. ' - ignor: used a flag for the error routine. when a drive is selected but
  69. '       not ready, the error routine gets control and opens a window that
  70. '       contains a RETRY button and possinly an IGNORE button.
  71. '       if ignor=0 then IGNORE button is NOT displayed; else it is displayed.
  72. '       selecting RETRY will cause the instruction that generated the
  73. '       "not ready" error to be retried. selecting IGNORE will pass control
  74. '       to the instruction after the one generating the error condition.
  75. ' - Ldrives: number of logical drives on the system
  76. ' - OneFlop: flag set (TRUE) if system has one floppy, else FALSE
  77.  
  78.  
  79. DIM SHARED dlett$, ignor, Ldrives, OneFlop
  80. '-----------------------------------------------------------------
  81.  
  82.  
  83. ON ERROR GOTO ErrorTrap    ' enable error routine
  84.  
  85. '-----------------------------------------------------------------
  86. ' get attribute from current screen so it can be restored upon exit
  87. OrigAttr = SCREEN(1, 1, 1)' save original attribute from row 1, col 1
  88.  
  89. '-------------------------------------------------------------------
  90. ' if WIDTH command is used, it must be placed before call to LangWinInit
  91. ' because code in LangWinInit extracts max rows/cols from screen and saves
  92. ' in global variables.
  93. WIDTH 80, 25
  94.  
  95. '----------------------------------------------------------------------
  96. ' these variables MUST be defined BEFORE call to LangWinInit.
  97. ' keep these as low as possible to conserve memory at run time.
  98. MaxWindows = 10       ' max simultaneous open windows
  99. MaxButtons = 40      ' max number of objects (including text labels) active
  100. MaxTextLines = 200   ' maximum number of text lines in any scrollable win
  101. MaxTextWins = 4      ' max windows that can have scrollable text
  102.                      ' must be <= MaxWindows
  103.  
  104. LOCATE , , 0         ' start with hidden text cursor
  105.  
  106. SCREEN 0, , 0, 0     ' text mode
  107.  
  108. CALL LangWinInit     ' initialize (if mouse exists, it will be displayed)
  109.                
  110.                      ' if you get "subscript out of range" error while
  111.                      ' in this routine, be sure you called QB with /ah.
  112.                      ' then try reducing the value of MaxWindows.
  113.                      ' check the WIDTH command; reduce number of columns,
  114.                      ' and/or number of rows.
  115.  
  116. '---------------------------------------------------------------------
  117. ' get actual number of logical drives on the system
  118.  
  119. ' get # drives from ChangeDrive (i.e., int 21h, function 0Eh).
  120. ' value will be max of 5 or # logical drives specified
  121. ' in LASTDRIVE parm in config.sys (i.e., LASTDRIVE=c will cause ChangeDrive
  122. ' to return 5, not 3, as # logical drives - that's a DOS quirk, not mine).
  123. ' LASTDRIVE=g will cause ChangeDrive to return a 7.
  124.  
  125. ' drives specified in LASTDRIVE parm, however, might not be actual
  126. ' number of drives on system (LASTDRIVE=z doesn't mean you have 26 drives)
  127. ' so, after we get LASTDRIVES value, we must determine how many logical
  128. ' drives really exist (without attempting to read from them
  129. ' which could produce a drive not ready error) - that is, we need to know
  130. ' how many drives are actually configured on the system, not how many
  131. ' are ready at this moment.
  132.  
  133. dd$ = GetCurDrive$         ' current default drive
  134. Ldrives = ChangeDrive(dd$) 'get LASTDRIVES value
  135.  
  136. ' now see how many drives are actually there
  137. ' step through each drive (starting with #1) and try to
  138. ' change to it with ChangeDrive. if successful, continue with loop.
  139. ' if unsuccessful, then previous drive was last drive on the system.
  140.  
  141. FOR i = 1 TO Ldrives
  142.     dl$ = CHR$(ASC("A") - 1 + i)   ' compute a drive letter
  143.     x = ChangeDrive(dl$)           ' try to change to it
  144.     IF x < 0 THEN                  ' successful?
  145.         Ldrives = i - 1   ' can't change to drive i, change value of ldrives
  146.         EXIT FOR          ' stop scan
  147.     END IF
  148. NEXT
  149. x = ChangeDrive(dd$) ' now change back to original drive
  150.  
  151. '--------------------------------------------------------------------
  152. ' on systems with only one physical floppy drive, it can be logically
  153. ' referenced as both A: and B: (dos handles this).
  154. ' however, if the A: drive is "active" and you try and access the B: drive,
  155. ' dos will display the following message:
  156. '    "Insert diskett for drive B: and press any key when ready"
  157. ' unfortunately, you cannot control the placement of this message and it will
  158. ' ruin an otherwise attractive display of windows.
  159.  
  160. ' if the system has one floppy, and either A: or B: is selected by user,
  161. ' i assume that both drive letters refer to the same physical drive,
  162. ' and i first make the appropriate logical letter "active" before the
  163. ' drive is accessed. this should avoid the dos message.
  164. ' a not ready condition will be detected, and an error window opened,
  165. ' if the A: or B: drive (which has been made active) is not ready
  166. ' (i.e., does not have a floppy inserted and the door closed).
  167.  
  168. ' the byte at &H504 is used to make either A: or B: active.
  169. ' if it is set to 0, then A: is active; if 1 then B: is active
  170. ' (assuming that there is only one floppy on the system).
  171. ' the word at &H410 contains info on system equipment.
  172. ' if bit 0 is set, then the system has floppies.
  173. ' in that case, bits 6 & 7 indicate the number of floppies minus 1
  174. ' (i.e., if bits 6 & 7 are 0, then system has 1 floppy drive).
  175.  
  176. ' first, lets see if this system has only one floppy drive
  177. OneFlop = FALSE     ' default for flag
  178. DEF SEG = 0         ' establish addressability to low memory
  179. IF (PEEK(&H410) AND &H1) = 1 THEN   ' test bit 0 to see if any floppies
  180.     ' floppies exist, see how many
  181.     ' set flag if only one
  182.     IF (PEEK(&H410) AND &HC0) = 0 THEN OneFlop = TRUE
  183. END IF
  184. DEF SEG              ' restore addressability
  185.  
  186. ' the OneFlop flag will